package com.hcss.common.util.excel.rull;

import org.apache.commons.lang3.StringUtils;

import lombok.extern.slf4j.Slf4j;

/**
 * @Title: 非空校验
 * @Description:
 * @Author:momo
 * @Since:2019年1月28日
 * @Version:1.1.0
 */
@Slf4j
public class NotNullRullType implements RullType {

	@Override
	public RullResult rull(RullData obj) throws Exception {
		if(null == obj.getColNum() || null == obj.getRowNum()) {
			log.error("rullData及相关数据不能为空！");
			throw new Exception("rullData及相关数据不能为空！");
		}
		Object data = obj.getObj();
		if(null == data) {
			return RullResult.getFailResult("第" + (obj.getRowNum() + 1) + "行，"+ ColIndexName.toIndexMain(obj.getColNum()) + "列数据为空，请检查！");
		}
		if(data instanceof String) {
			String temp = (String) data;
			if(StringUtils.isEmpty(temp))
				return RullResult.getFailResult("第" + (obj.getRowNum() + 1) + "行，"+ ColIndexName.toIndexMain(obj.getColNum()) + "列数据为空，请检查！");
		}
		return RullResult.getSuccResult();
	}
	
}

